/*
 * Copyright 2012 Marsrutai.lt
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *   http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package lt.marsrutai.mobile.android.activity.intent;

import java.util.ArrayList;
import java.util.List;

import lt.marsrutai.mobile.android.activity.FastestRoutesSearchActivity;
import lt.marsrutai.mobile.android.widget.DialogChoiceItem;
import lt.marsrutai.mobile.android.widget.FastestRouteSearchDialogItem;
import android.app.Activity;
import android.content.Intent;
import android.location.Location;
import android.os.Bundle;

public class FastestRoutesSearchIntentHolder extends IntentHolder {

    private static final String TRANSPORT_TYPES = "transportTypes";
    private static final String START = "start";
    private static final String START_LOCATION = "startLocation";
    private static final String START_SELECTION_TYPE = "startSelectionType";
    private static final String END = "end";
    private static final String END_LOCATION = "endLocation";
    private static final String END_SELECTION_TYPE = "endSelectionType";
    private static final String IS_ARRIVAL_IND = "isArrivalInd";
    private static final String CHANGE_COUNT = "changeCount";
    private static final String CHANGE_DURATION = "changeDuration";
    private static final String WALK_DISTANCE = "walkDistance";
    private static final String WALK_SPEED = "walkSpeed";
    private static final String IS_TIME_SET_BY_USER = "isTimeSetByUser";
    private static final String SELECTED_LOCATION = "selectedLocation";
    private static final String STOP_NAMES = "stopNames";
    private static final String SELECTED_DATE = "selectedDate";
    private static final String SCOPE_FOLDER = "scopeFolder";
    private static final String DIALOG_OWNER_ID = "dialogOwnerId";
    private static final String DIALOG_TITLE = "title";
    private static final String DIALOG_CHOICES = "dialogChoices";

    public FastestRoutesSearchIntentHolder(Activity sourceActivity) {
        super(sourceActivity, FastestRoutesSearchActivity.class);
    }

    public FastestRoutesSearchIntentHolder(Intent intent) {
        super(intent);
    }

    public FastestRoutesSearchIntentHolder(Bundle bundle) {
        super(bundle);
    }

    public void setScopeFolder(String scopeFolder) {
        intent.putExtra(SCOPE_FOLDER, scopeFolder);
    }

    public String getScopeFolder() {
        return intent.getStringExtra(SCOPE_FOLDER);
    }

    public void setDialogTitle(String title) {
        intent.putExtra(DIALOG_TITLE, title);
    }

    public String getDialogTitle() {
        return intent.getStringExtra(DIALOG_TITLE);
    }

    public void setDialogOwnerId(String ownerId) {
        intent.putExtra(DIALOG_OWNER_ID, ownerId);
    }

    public String getDialogOwnerId() {
        return intent.getStringExtra(DIALOG_OWNER_ID);
    }

    public void setDialogChoices(DialogChoiceItem[] dialogChoices) {
        setCollection(DIALOG_CHOICES, dialogChoices);
    }

    public DialogChoiceItem[] getDialogChoices() {
        return getArray(DIALOG_CHOICES, DialogChoiceItem.class);
    }

    public void setCurrentlySelectedDate(long time) {
        intent.putExtra(SELECTED_DATE, time);
    }

    public long getCurrentlySelectedDate() {
        return intent.getLongExtra(SELECTED_DATE, 0);
    }

    public void setStopNames(List<String> stopNames) {
        if (stopNames != null) {
            intent.putStringArrayListExtra(STOP_NAMES, new ArrayList<String>(stopNames));
        }
    }

    public List<String> getStopNames() {
        return intent.getStringArrayListExtra(STOP_NAMES);
    }

    public void setSelectedLocation(Location location) {
        intent.putExtra(SELECTED_LOCATION, location);
    }

    public Location getSelectedLocation() {
        return intent.getParcelableExtra(SELECTED_LOCATION);
    }

    public void setIsTimeSetByUser(boolean isTimeSetByUser) {
        intent.putExtra(IS_TIME_SET_BY_USER, isTimeSetByUser);
    }

    public boolean getIsTimeSetByUser() {
        return intent.getBooleanExtra(IS_TIME_SET_BY_USER, false);
    }

    public void setStart(String value) {
        intent.putExtra(START, value);
    }

    public String getStart() {
        return intent.getStringExtra(START);
    }

    public void setStartLocation(Location value) {
        if (value != null) {
            intent.putExtra(START_LOCATION, value);
        }
    }

    public Location getStartLocation() {
        return intent.getParcelableExtra(START_LOCATION);
    }

    public void setStartSelectionType(FastestRouteSearchDialogItem value) {
        if (value != null) {
            intent.putExtra(START_SELECTION_TYPE, value.name());
        }
    }

    public FastestRouteSearchDialogItem getStartSelectionType() {
        String value = intent.getStringExtra(START_SELECTION_TYPE);

        if (value != null) {
            return FastestRouteSearchDialogItem.valueOf(value);
        }

        return null;
    }

    public void setEnd(String value) {
        intent.putExtra(END, value);
    }

    public String getEnd() {
        return intent.getStringExtra(END);
    }

    public void setEndLocation(Location value) {
        if (value != null) {
            intent.putExtra(END_LOCATION, value);
        }
    }

    public Location getEndLocation() {
        return intent.getParcelableExtra(END_LOCATION);
    }

    public void setEndSelectionType(FastestRouteSearchDialogItem value) {
        if (value != null) {
            intent.putExtra(END_SELECTION_TYPE, value.name());
        }
    }

    public FastestRouteSearchDialogItem getEndSelectionType() {
        String value = intent.getStringExtra(END_SELECTION_TYPE);

        if (value != null) {
            return FastestRouteSearchDialogItem.valueOf(value);
        }

        return null;
    }

    public void setIsArrivalInd(boolean value) {
        intent.putExtra(IS_ARRIVAL_IND, value);
    }

    public boolean getIsArrivalInd() {
        return intent.getBooleanExtra(IS_ARRIVAL_IND, false);
    }

    public void setChangeCount(Integer value) {
        if (value != null) {
            intent.putExtra(CHANGE_COUNT, value);
        }
    }

    public Integer getChangeCount() {
        if (intent.getExtras().containsKey(CHANGE_COUNT)) {
            return intent.getIntExtra(CHANGE_COUNT, 0);
        }
        return null;
    }

    public void setChangeDuration(Integer value) {
        if (value != null) {
            intent.putExtra(CHANGE_DURATION, value);
        }
    }

    public Integer getChangeDuration() {
        if (intent.getExtras().containsKey(CHANGE_DURATION)) {
            return intent.getIntExtra(CHANGE_DURATION, 0);
        }
        return null;
    }

    public void setWalkDistance(Integer value) {
        if (value != null) {
            intent.putExtra(WALK_DISTANCE, value);
        }
    }

    public Integer getWalkDistance() {
        if (intent.getExtras().containsKey(WALK_DISTANCE)) {
            return intent.getIntExtra(WALK_DISTANCE, 0);
        }
        return null;
    }

    public void setWalkSpeed(Integer value) {
        if (value != null) {
            intent.putExtra(WALK_SPEED, value);
        }
    }

    public Integer getWalkSpeed() {
        if (intent.getExtras().containsKey(WALK_SPEED)) {
            return intent.getIntExtra(WALK_SPEED, 0);
        }
        return null;
    }
    
    public void setTransportTypes(List<String> value) {
        if (value != null) {
            intent.putStringArrayListExtra(TRANSPORT_TYPES, new ArrayList<String>(value));
        }
    }
    
    public List<String> getTransportTypes() {
        return intent.getStringArrayListExtra(TRANSPORT_TYPES);
    }

}
